<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netty 设计模式深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .pattern-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.18);
        }
        
        .pattern-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .pattern-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        .section-title {
            position: relative;
            display: inline-block;
            margin-bottom: 2rem;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .code-inline {
            background: #f3f4f6;
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 0.9em;
            color: #6366f1;
        }
        
        .floating-shape {
            position: absolute;
            opacity: 0.1;
            animation: float 6s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-20px); }
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 relative overflow-hidden">
        <div class="floating-shape top-10 right-10 text-9xl">
            <i class="fas fa-network-wired"></i>
        </div>
        <div class="floating-shape bottom-10 left-10 text-8xl" style="animation-delay: 3s;">
            <i class="fas fa-code"></i>
        </div>
        
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Netty 设计模式深度解析
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    探索高性能网络框架背后的设计智慧
                </p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-layer-group mr-2"></i>
                        <span>8大核心模式</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-rocket mr-2"></i>
                        <span>高性能架构</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-puzzle-piece mr-2"></i>
                        <span>灵活可扩展</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="container mx-auto max-w-6xl">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">引言</h2>
                <p class="text-lg text-gray-700 leading-relaxed indent-8">
                    Netty 是一个高性能的网络通信框架，广泛应用于构建高效、可扩展的网络应用。在 Netty 的设计中，多个经典的设计模式被有效地应用，以解决复杂的网络编程问题。让我们深入探索这些设计模式如何在 Netty 中发挥作用，共同构建出这个强大的网络框架。
                </p>
            </div>
        </div>
    </section>

    <!-- Design Patterns Visualization -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="container mx-auto max-w-6xl">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-8 text-center">设计模式关系图</h2>
            <div class="mermaid">
                graph TB
                    A[Netty Framework] --> B[观察者模式]
                    A --> C[责任链模式]
                    A --> D[策略模式]
                    A --> E[工厂模式]
                    A --> F[建造者模式]
                    A --> G[代理模式]
                    A --> H[适配器模式]
                    A --> I[模板方法模式]
                    
                    B --> B1[ChannelHandler事件传递]
                    C --> C1[ChannelPipeline处理链]
                    D --> D1[I/O操作策略]
                    E --> E1[Channel/Handler创建]
                    F --> F1[Bootstrap配置]
                    G --> G1[Channel访问控制]
                    H --> H1[Handler适配]
                    I --> I1[抽象类模板]
                    
                    style A fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff
                    style B fill:#f093fb,stroke:#f5576c,stroke-width:2px,color:#fff
                    style C fill:#4facfe,stroke:#00f2fe,stroke-width:2px,color:#fff
                    style D fill:#fa709a,stroke:#fee140,stroke-width:2px,color:#fff
                    style E fill:#30cfd0,stroke:#330867,stroke-width:2px,color:#fff
                    style F fill:#a8edea,stroke:#fed6e3,stroke-width:2px,color:#333
                    style G fill:#ffecd2,stroke:#fcb69f,stroke-width:2px,color:#333
                    style H fill:#ff9a9e,stroke:#fecfef,stroke-width:2px,color:#fff
                    style I fill:#fbc2eb,stroke:#a6c1ee,stroke-width:2px,color:#333
            </div>
        </div>
    </section>

    <!-- Design Patterns Grid -->
    <section class="py-16 px-6">
        <div class="container mx-auto max-w-6xl">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-12 text-center">核心设计模式详解</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- 观察者模式 -->
                <div class="pattern-card rounded-xl p-8">
                    <div class="pattern-icon">
                        <i class="fas fa-eye"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-4">
                        1. 观察者模式
                        <span class="text-sm text-gray-500 ml-2">Observer Pattern</span>
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-cog mr-2"></i>应用场景
                            </h4>
                            <p class="text-gray-700">
                                Netty 使用观察者模式来处理事件的传递。尤其在 <span class="code-inline">ChannelHandlerContext</span> 和 <span class="code-inline">ChannelHandler</span> 之间的事件传递过程中，事件会从一个 <span class="code-inline">ChannelHandler</span> 传递到下一个 <span class="code-inline">ChannelHandler</span>，形成一个处理链。
                            </p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-star mr-2"></i>核心作用
                            </h4>
                            <p class="text-gray-700">
                                允许多个观察者（<span class="code-inline">ChannelHandler</span>）注册到事件源（<span class="code-inline">Channel</span>），并在事件发生时收到通知，这种模式提高了事件处理的灵活性和可扩展性。
                            </p>
                        </div>
                    </div>
                </div>

                <!-- 责任链模式 -->
                <div class="pattern-card rounded-xl p-8">
                    <div class="pattern-icon">
                        <i class="fas fa-link"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-4">
                        2. 责任链模式
                        <span class="text-sm text-gray-500 ml-2">Chain of Responsibility</span>
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-cog mr-2"></i>应用场景
                            </h4>
                            <p class="text-gray-700">
                                Netty 中的 <span class="code-inline">ChannelPipeline</span> 实现了责任链模式。<span class="code-inline">ChannelPipeline</span> 由多个 <span class="code-inline">ChannelHandler</span> 组成，数据和事件会沿着链条传递，每个 <span class="code-inline">ChannelHandler</span> 负责处理特定的任务。
                            </p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-star mr-2"></i>核心作用
                            </h4>
                            <p class="text-gray-700">
                                使得处理链可以动态添加或移除处理器，且每个处理器只负责自己的一部分任务，提高了系统的灵活性和可维护性。
                            </p>
                        </div>
                    </div>
                </div>

                <!-- 策略模式 -->
                <div class="pattern-card rounded-xl p-8">
                    <div class="pattern-icon">
                        <i class="fas fa-chess"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-4">
                        3. 策略模式
                        <span class="text-sm text-gray-500 ml-2">Strategy Pattern</span>
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-cog mr-2"></i>应用场景
                            </h4>
                            <p class="text-gray-700">
                                Netty 在选择和执行不同的 I/O 操作策略时使用策略模式。不同的 I/O 操作（如选择器、线程池策略）由不同的策略实现类来完成。
                            </p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-purple-600 mb-2">
                                <i class="fas fa-star mr-2"></i>核心作用
                            </h4>
                            <p class="text-gray-700">
                                使得不同的策略可以互相替换，能够根据具体需求选择适当的策略实现，从而提高了系统的灵活性和扩展性。
                            </p>
                        </div>
                    </div>
                </div>

                <!-- 工厂模式 -->
                <div class="pattern-card rounded-xl p-8">
                    <div class="pattern-icon">
                        <i class="fas fa-industry"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-4">
                        4. 工厂模式
                        <span class="text-sm text-gray-500 ml-2